package Utils;

import org.apache.lucene.document.Document;

/*
 * This class is used to encode verse id, book id and other informations
 * to allow the fetch of the desired document in the collecion.
 * It includes methods to encode an url (b:yy;v:xx;...)
 * and to decode it
 */
public class VerseInfoEncoder {

	private final String SEPARATOR = "&";

	public String encode(Document d) {
		String encodedUrl = "";		
		String fileName = d.get("fileName");
		String bookID = d.get("bookId");
		String verseID = d.get("verseID");
		String maxInCollection = d.get("maxInCollection");
		encodedUrl = fileName + SEPARATOR +  bookID + SEPARATOR + verseID + SEPARATOR + maxInCollection;
		//System.out.println(encodedUrl);
		return encodedUrl;
	}

	public final String decodeFileName(String encodedInfo) {
		String fileName = encodedInfo.split(SEPARATOR)[0];
		System.out.println("Requested fileName: " + fileName);
		return fileName;
	}

	public int decodeBookId(String encodedInfo) {
		String bookIdString = encodedInfo.split(SEPARATOR)[1];
		return new Integer(bookIdString).intValue();
	}

	public int decodeVerseID(String encodedInfo) {
		String verseIdString = encodedInfo.split(SEPARATOR)[2];
		return new Integer(verseIdString).intValue();
	}
	
	public int decodeMaxInCollection(String encodedInfo) {
		String maxInCollection = encodedInfo.split(SEPARATOR)[3];
		return new Integer(maxInCollection).intValue();
	}
	
	
	
}
